<?
require_once '../home/config.php';
ob_clean();
?>
<?
class rss{
	var $title;
	var $content;
	var $main_link;

	/*
	Khởi tạo class
	*/
	function rss($title, $main_link=""){
		$this->title 		= $title;
		$this->main_link 	= $main_link;
		$this->content 	= "";
        $this->copyright = 'VnUpdate.net';
        $this->generator = 'VnUpdate';
	}

	/*
	Print header
	*/
	function rss_header(){
		$today = getdate();

		$header = '<?xml version="1.0" encoding="utf-8"?>' . "\n" .
				    '<rss version="2.0">' . "\n" .
					 '	<channel>'  . "\n" .
					 '		<title>' . htmlspecialchars($this->title) . '</title>' . "\n" .
                     '		<copyright>' . htmlspecialchars($this->copyright) . '</copyright>' . "\n" .
                     '		<generator>' . htmlspecialchars($this->generator) . '</generator>' . "\n" .
					 '		<link>' . htmlspecialchars($this->main_link) . '</link>' . "\n" .
					 '		<pubDate>' . date("D, d M Y H:i:s ",$today[0]) . "GMT+7" . '</pubDate>' . "\n" .
					 '		<lastBuildDate>' . date("D, d M Y H:i:s ",$today[0]) . "GMT+7" . '</lastBuildDate>' . "\n";

		return $header;
	}

	/*
	Add item
	*/
	function additem($title, $description, $link, $guid = '' , $pubdate){
		$item = '			<item>' . "\n" .
				  '				<title>' . htmlspecialchars($title) . '</title>' . "\n" .
				  '				<description><![CDATA[' . $description . ']]></description>' . "\n" .
				  '				<link>' . htmlspecialchars($link) . '</link>' . "\n" .
                  '				<guid isPermaLink="false">' . htmlspecialchars($guid) . '</guid>' . "\n" .
				  '				<pubDate>' . htmlspecialchars($pubdate) . '</pubDate>' . "\n" .
				  '			</item>' . "\n";

		//return $item;
		$this->content .= $item;
	}

	/*
	Print header
	*/
	function rss_footer(){
		$footer = '	</channel>' . "\n" .
					 '</rss>';

		return $footer;
	}

	/*
	lấy nội dung rss
	*/
	function getRSSContent(){
		return $this->rss_header() .
				 $this->content .
				 $this->rss_footer();
	}

	/*
	Save RSS to file
	*/
	function saveRSS($filename){
		$handle = fopen($filename, 'w');
		fwrite($handle, $this->getRSSContent());
		fclose($handle);
	}
}
//lấy content
$page_title = 'Trang chủ - VnUpdate';
$domain = 'http://vnupdate.net';
$rss = new rss($page_title,$domain);
$db_listnews = new db_query('SELECT new_id,new_title,new_date,new_picture,new_teaser,new_detail,
                                    new_cat_id,cat_id,cat_name
                                FROM news 
                                LEFT JOIN categories_multi ON cat_id = new_cat_id 
                                WHERE 1
                                ORDER BY new_date DESC 
                                LIMIT 20');
$listNews = $db_listnews->resultArray();
foreach($listNews as $news){
    $description = '<div align="center"><a href="'.$domain.generate_detail_url($news,GetNamecat($news['new_cat_id'])).'"><img width="400" src="'.$news['new_picture'].'" /></a></div><br />'.$news['new_teaser'] != '' ? cut_string(removeHTML($news['new_teaser']),100) : cut_string(removeHTML($news['new_detail']),100);
    $rss->additem($news['new_title'],$description,''.$domain.generate_detail_url($news,GetNamecat($news['new_cat_id'])),''.$domain.generate_detail_url($news,GetNamecat($news['new_cat_id'])),date('d/m/Y h:i:s a'));    
}
?>
<?header ("Content-Type:text/xml");?>
<?=$rss->getRSSContent()?>